package base.thread;

public class OriginalCounterTest extends Thread {

	private OriginalCoun coun;
	private int delay;

	public OriginalCounterTest(OriginalCoun coun,int delay) {
		this.coun = coun;
		this.delay=delay;
	}

	public void run() {
		coun.decrement(100,delay);
	}

	public static void main(String[] args) {
		OriginalCoun coun = new OriginalCoun();
		new OriginalCounterTest(coun,1000).start();
		new OriginalCounterTest(coun,0).start();
	}
}

class OriginalCoun {
	private double balance = 100;

	public void increment(double money) {
		balance += money;
	}

	public void decrement(double money,int delay) {
		if(balance>=money){
			try {
				Thread.sleep(delay);
				balance -= money;
				System.out.println(Thread.currentThread().getName()+" dec "+ money+" success");
			} catch (Exception e) {
			}
			
		}else{
			
			System.out.println(Thread.currentThread().getName()+" dec fail");
		}
	}
}
